<?php

namespace app\common\validate;

use app\common\validate\Base;

class Admin extends Base
{

    protected $rule = [
        'id|管理员ID' => 'require|integer',
        'username|管理员用户名' => 'require|alphaDash|min:5',
        'password|登录密码' => 'require|length:6,16',
        'repassword|重复登录密码' => 'require|confirm:password',
        'group_id|用户组' => 'require|integer|checkGroupId',
        'disable|状态' => 'require|in:1,0',
        'phone|手机号码' => 'length:11',
    ];

    protected $message = [
        'rpassword.eq' => '重复登录密码输入错误',
        'rsafe_password.eq' => '重复安全密码密码输入错误',
    ];

    protected $scene = [
        // 后台新增
        'manage_add' => ['username','password','repassword','group_id','disable'],
        // 后台编辑
        'manage_edit' => ['id'],
    ];

    protected function checkGroupId($v,$rule,$data){
        $group = \app\common\query\AdminGroup::adminGroupData($v);
        if($group==false){
            $this->message['group_id.checkGroupId'] = '用户组不存在';
            return false;
        }else{
            return true;
        }
    }

}